/******************************************************************************
 *
 * Project:		mGameEngine
 * File:		hdr.cpp
 * Author:		twoja stara
 * Created on:	2009-09-20
 *
 ******************************************************************************/

#include "hdr.h"

namespace mGameEngine
{
namespace Graphics
{

HighDynamicRange::HighDynamicRange(float strength,
								const Texture *texture,
								RenderTarget *target) :
	PostProcess(NULL, texture, target),
	_strength(strength)
{
	static const String &vertSrc
	(
#include "postprocess.vert"
	);
	static const String &fragSrc
	(
#include "hdr.frag"
	);
	_gpuProgram = new GPUProgram(vertSrc, fragSrc);
	_gpuProgram->compile();
}

HighDynamicRange::~HighDynamicRange()
{
	delete _gpuProgram;
}

void HighDynamicRange::setStrength(float strength)
{
	if(strength < 0.0f)
	{
		return;
	}

	_strength = strength;
}

void HighDynamicRange::process() const
{
	if(!_enabled || !_output)
	{
		return;
	}

	// set params
	_gpuProgram->setValue("strength", _strength);
	_gpuProgram->setVector("pixSize", Vector2(1.0f, 1.0f) / _output->getSize());

	PostProcess::process();
}

}
}

